package com.bytedance.scenedemo.navigation.push_pop;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.*;

/**
 * Created by JiangQi on 7/30/18.
 */
public class PushPopBasicUsageDemoScene extends Scene {
    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_push_pop_basic_usage_demo,container,false);
        ScrollView svMain= (ScrollView) layout.findComponentById(ResourceTable.Id_sv_push_pop_basic_usage_main);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_push_pop_basic_usage_hint);
        Button btnGoTo= (Button) layout.findComponentById(ResourceTable.Id_btn_push_pop_basic_usage_goto);
        int value=0;
        if(getArguments()!=null){
            value= (int) getArguments().getParam("value");
        }
        svMain.setBackground(ColorUtil.getMaterialColor(value));
        textHint.setText(getClassName());
        btnGoTo.setText(""+value);

        int finalValue = value;
        btnGoTo.setClickedListener(component -> {
            IntentParams intentParams=new IntentParams();
            intentParams.setParam("value", finalValue +1);
            SceneExtensions.requireNavigationScene(this).push(PushPopBasicUsageDemoScene.class,intentParams);
        });
        return layout;
    }
}
